package com.woniuxy.demo01.demos.web;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 作者
 * @create 2025-08-22 16:09
 */
@RequestMapping("/mytest")
@RestController
public class MyController {
    //  localhost:8080/mytest/login?name=xxx&pwd=yyy
    @RequestMapping("/login")
    public String login(HttpServletRequest request){
        Object name = request.getParameter("name");
        Object pwd = request.getParameter("pwd");
        System.out.println("服务器收到了用户的请求数据");
        System.out.println("name:"+name);
        System.out.println("pwd:"+pwd);
        return "login success";
    }

    //JSON格式
    //{"name":"xxx","age":"123"}
    @RequestMapping("/reg")
    public String reg(@RequestBody User user){

        System.out.println("服务器收到了用户的请求数据");
        System.out.println("User:"+user);
        return "reg success";
    }
}
